<template>
  <div>
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :before-close="childOperation">
      <!-- 内容主体区域 -->
      <el-form :model="addForm" ref="addFormRef" label-width="70px">
        <el-form-item label="用户名">
          <el-input v-model="addForm.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="addForm.password"></el-input>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="addForm.email"></el-input>
        </el-form-item>
        <el-form-item label="手机">
          <el-input v-model="addForm.mobile"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="childOperation">取 消</el-button>
        <el-button type="primary" @click="addOperation(addForm)">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible: false,
      // 添加用户的表单数据
      addForm: {
        username: "",
        password: "",
        email: "",
        mobile: "",
      },
    };
  },
  props: ["showDig", "EditDia"],
  methods: {
    handleClose() {},
    addOperation(addForm) {
      console.log(addForm);

      this.$axios.post("/users", addForm).then((res) => {
        console.log(res);
        if (res.data.meta.status == 201) {
          this.$message({
            message: res.data.meta.msg,
            type: "success",
          });
        } else {
          this.$message.error("创建失败");
        }
      });
      this.$refs.addFormRef.resetFields();
      this.$emit("aaa");
      this.$emit('shuaxin')
    },
    childOperation() {
      this.$refs.addFormRef.resetFields();
      this.$emit("aaa");
    },
  },
  watch: {
    showDig: function (newval, oldval) {
      this.dialogVisible = newval;
      console.log(newval)
       this.edit=true
    }
  },
};
</script>
<style lang='scss' scoped>
</style>